import os

names = set([])

path = '/tmp/food-pic-300-2'
path2 = '/tmp/pic-300-1'
for name in set([ line for line in os.popen("ls "+path).read().split("\n")]):
    if len(name) == 0: continue
    sects = name.split("-")
    names.add("-".join(sects[:-1]))

fname = 'new_pic_id_2.csv'
fname2 = 'new_pic_id.csv'
with open(fname,"w") as f:
    for i,line in enumerate(names):
        if len(line) < 2: continue
        #num = i + 70000
        num = i + 100000
        sent = line.replace('"',"'")#.replace(")","\)")
        f.write("%d\t%s\n"%(num,line))
        cmd = "mkdir ./static/%d"%num
        os.system(cmd)
        cmd = "rm -f ./static/%d/*.jpg"%num
        os.system(cmd)
        cmd = '''cp "%s/%s"* ./static/%d/'''%(path,sent,num)
        print(cmd)
        os.system(cmd)
        cmd = '''mv "./static/%d/%s-1.jpg" "./static/%d/%s.jpg"'''%(num,sent,num,sent)
        os.system(cmd)
